﻿using RXY_Mall.Application.Manager;
using RXY_Mall.Application.Manager.Dto;
using RXY_Mall.Shop.Authorize;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace RXY_Mall.Shop.Controllers
{
    public class BFP_AccountController : Controller
    {
        protected IManagerService _managerService;
        public BFP_AccountController()
        {
            _managerService = new ManagerService();
        }
        [AllowAnonymous]
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        //[AllowAnonymous]
        public ActionResult Login(string userName, string password)
        {
            var res = _managerService.ShopAdminLogin(userName, password);
            if (res.code==1)
            {

                    UserCookie userCookie = new UserCookie();
                    userCookie.Id = res.data.Id;
                    userCookie.UserName = res.data.UserName;
                    userCookie.ShopId = res.data.ShopId;
                    userCookie.Token = res.data.Token;
                    var authorizeCookie = AuthorizeHelper.AddUserCookie(userCookie, true);
                    Response.Cookies.Add(authorizeCookie);
                    //return RedirectToAction("Index", "Home");

            }

            return Json(res);
        }

        public virtual ActionResult LogOff()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Login", "BFP_Account");
        }
    }
}